﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Krile.Forms.ConfigForm.Children.Controls
{
    public partial class ColorConfigure : UserControl
    {
        public Color Value
        {
            get { return ColorButton.BackColor; }
            set { ColorButton.BackColor = value; }
        }

        public bool TreatEnabled
        {
            get { return enabledSwitch.Visible; }
            set
            {
                enabledSwitch.Checked = true;
                enabledSwitch.Visible = value;
            }
        }

        public bool ColorEnabled
        {
            get { return enabledSwitch.Checked; }
            set
            {
                enabledSwitch.Checked = value;
                enabledSwitch_CheckedChanged(null, null);
            }
        }

        public ColorConfigure(string desc, Color value)
        {
            InitializeComponent();
            this.Value = value;
            this.Description.Text = desc;
            TreatEnabled = false;
        }

        public ColorConfigure(string desc, Color value, bool enabled)
        {
            InitializeComponent();
            this.Value = value;
            this.Description.Text = desc;
            TreatEnabled = true;
            ColorEnabled = enabled;
        }

        private void ColorButton_Click(object sender, EventArgs e)
        {
            using (var cd = new ColorDialog())
            {
                cd.Color = Value;
                cd.AllowFullOpen = true;
                cd.AnyColor = true;
                if (cd.ShowDialog() == DialogResult.OK)
                {
                    Value = cd.Color;
                }
            }
        }

        private void enabledSwitch_CheckedChanged(object sender, EventArgs e)
        {
            ColorButton.Enabled = enabledSwitch.Checked;
        }
    }
}
